package two.chapter_2.c2_1;

public abstract class Sortable<Item extends Comparable<Item>> {

    public abstract void sort(Item [] items);
    public  boolean isSorted(Item [] items){
        for (int i=0;i<items.length-1;i++){
            if (less(items[i+1],items[i])){
                return false;
            }
        }
        return true;
    }
    public boolean less(Item a,Item b){
        return a.compareTo(b)<0;
    }

    public void exch(int indexA,int indexB,Item[] items){
        Item t=items[indexA];
        items[indexA]=items[indexB];
        items[indexB]=t;
    }
}
